<?php
/*
 * timeline.js.php
 * Description: JavaScript for the SIMILE Timline Plugin
 * Plugin URI: http://www.freshlabs.de/journal/archives/2006/10/wordpress-plugin-simile-timeline/
 * Author: Tim Isenheim
 */
include_once('../../../../wp-config.php');
header("Cache-Control: public");
header("Pragma: cache");

$offset = 60*60*24*60;
$ExpStr = "Expires: ".gmdate("D, d M Y H:i:s",time() + $offset)." GMT";
$LmStr = "Last-Modified: ".gmdate("D, d M Y H:i:s",filemtime(__FILE__))." GMT";

header($ExpStr);
header($LmStr);
header('Content-Type: text/javascript; charset: UTF-8');
?>


var t1;
function loadSimileTimeline() {
	
  if(document.getElementById("stl-timeline")){	
	  var eventSource = new Timeline.DefaultEventSource();
	  var bandInfos = [
	    Timeline.createBandInfo({
	        eventSource:    eventSource,
	        date:           "<?php echo date('M d Y H:i:s'); echo " GMT"  . date('O'); ?>",
	        width:          "70%", 
	        intervalUnit:   Timeline.DateTime.MONTH, 
	        intervalPixels: 100
	    }),
	    Timeline.createBandInfo({
	    	    showEventText:  false,
	        trackHeight:    0.5,
	        trackGap:       0.2,
	        eventSource:    eventSource,
	        date:           "<?php echo date('M d Y H:i:s'); echo " GMT"  . date('O'); ?>",
	        width:          "30%", 
	        intervalUnit:   Timeline.DateTime.YEAR, 
	        intervalPixels: 200
	    })
	  	/* ----------------------------------
	  	 * Suggestions (still testing):
	  	 * If there are more than 3 posts a day > create an HOUR HotZone
	  	 * If there are more than 6 posts a week > create a DAY HotZone
	  	 * If there are more than 9 posts a month > create a WEEK HotZone
	  	 * -------------------------------------
	  	 
	    Timeline.createHotZoneBandInfo({
	        zones: [
	            {   start:    "Oct 01 2006 00:00:00 GMT-0500",
	                end:      "Nov 01 2006 00:00:00 GMT-0500",
	                magnify:  10,
	                unit:     Timeline.DateTime.WEEK
	            },
	            {   start:    "Aug 02 2006 00:00:00 GMT-0500",
	                end:      "Aug 04 2006 00:00:00 GMT-0500",
	                magnify:  7,
	                unit:     Timeline.DateTime.DAY
	            },
	            {   start:    "Aug 02 2006 06:00:00 GMT-0500",
	                end:      "Aug 02 2006 12:00:00 GMT-0500",
	                magnify:  5,
	                unit:     Timeline.DateTime.HOUR
	            }
	        ],
	        timeZone:       +2,
	        eventSource:    eventSource,
	        date:           "<?php echo date('M d Y H:i:s'); echo " GMT"  . date('O'); ?>",
	        width:          "70%", 
	        intervalUnit:   Timeline.DateTime.MONTH, 
	        intervalPixels: 100
	    }),
	    Timeline.createHotZoneBandInfo({
	        zones: [
	            {   start:    "Oct 01 2006 00:00:00 GMT-0500",
	                end:      "Nov 01 2006 00:00:00 GMT-0500",
	                magnify:  20,
	                unit:     Timeline.DateTime.WEEK
	            }
	        ],
	    	    showEventText:  false,
	    	    timeZone:       +2,
	        trackHeight:    0.5,
	        trackGap:       0.2,
	        eventSource:    eventSource,
	        date:           "<?php echo date('M d Y H:i:s'); echo " GMT"  . date('O'); ?>",
	        width:          "30%", 
	        intervalUnit:   Timeline.DateTime.YEAR, 
	        intervalPixels: 200
	    })*/

	  ];
	
	  bandInfos[1].syncWith = 0;
	  bandInfos[1].highlight = true;
	  bandInfos[1].eventPainter.setLayout(bandInfos[0].eventPainter.getLayout());
	  tl = Timeline.create(document.getElementById("stl-timeline"), bandInfos);
	  Timeline.loadXML("<?php bloginfo('stylesheet_directory'); ?>/plugins/timeline.xml.php", function(xml, url) { eventSource.loadXML(xml, url); });
	  
  }else{ /* empty - do nothing when no timeline-frame is found */ }
}

var resizeTimerID = null;
function resizeSimileTimeline() {
    if (resizeTimerID == null) {
        resizeTimerID = window.setTimeout(function() {
            resizeTimerID = null;
            tl.layout();
        }, 500);
    }
}

/* addEvent function - by Scott Andrew 
 * http://www.scottandrew.com/weblog/articles/cbs-events
 */
function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	} else { 
		return false; 
	} 
}

// use cool onload observer if prototype.js is installed
if(Event.observe){
	Event.observe(window, "load", loadSimileTimeline);
	Event.observe(window, "resize", resizeSimileTimeline);
}
// otherwise fall back to non-standard addEvent
else{ 
	addEvent(window, "load", loadSimileTimeline);
	addEvent(window, "resize", resizeSimileTimeline);
}